package com.devshephard.rpcframework.rpc.factory.base;

import com.devshephard.rpcframework.rpc.enums.RequestType;
import com.devshephard.rpcframework.rpc.service.rpcservice.impl.original.RpcServiceHttpImplOriginal;
import com.devshephard.rpcframework.rpc.service.rpcservice.impl.RpcServiceTcpImpl;
import com.devshephard.rpcframework.rpc.service.rpcservice.impl.original.RpcServiceTcpImplOriginal;
import org.springframework.stereotype.Component;

@Component
public class RpcBaseCustomFactory {

    public <T> Object rpcServiceProxyBuilder(Class<T> proxyTarget) throws Exception {

        Object proxyObj = new RpcServiceHttpImplOriginal<>(proxyTarget).getObject();

        return proxyObj;

    }

    public <T> Object rpcServiceProxyBuilderRequest(Class<T> proxyTarget, String requestType) throws Exception {

        if (RequestType.TCP.getDesc().equals(requestType)) { //使用基于Netty的TCP请求

           return new RpcServiceTcpImplOriginal<>(proxyTarget).getObject();

        }

        //默认返回HTTP请求方式
        return new RpcServiceHttpImplOriginal<>(proxyTarget).getObject();

    }

}
